import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { FootBallTimeVo } from "../view/footballGuess/vo/FootBallTimeVo";
import { ClockManager } from "../manager/ClockManager";
import { Language } from "../../../extend/language/Language";
import { FootBallGameConst } from "../view/footballGuess/FootBallGameConst";
type int = number;
//class FootBallTimeConfig
    
    export  class FootBallTimeConfig
    {
        constructor()
        {
            
            if (FootBallTimeConfig._instance) 
            {
                throw new Error("");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_football_time.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            this._footballTimeMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._list = [];
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new FootBallTimeVo();
                loc1.write(loc2);
                this._footballTimeMap[loc1.type + this.separator + loc1.group] = loc1;
                this._list.push(loc1);
            }
            this._list.sortOn("guessEndTime", Array.NUMERIC);
            return;
        }

        public getVoByTypeAndGroup(arg1: int, arg2: int): FootBallTimeVo
        {
            return this._footballTimeMap[arg1 + this.separator + arg2] as FootBallTimeVo;
        }

        public isInGuessTime(arg1: int, arg2: int): Boolean
        {
            var loc1=this.getVoByTypeAndGroup(arg1, arg2);
            var loc2=ClockManager.instance.nowDate.getTime();
            if (loc1) 
            {
                if (loc1.guessEndTime > loc2 && loc2 >= loc1.guessStartDate.time) 
                {
                    return true;
                }
            }
            return false;
        }

        public getCurGuess(): int
        {
            var loc2=null;
            var loc1=this._list.length;
            var loc3=ClockManager.instance.nowDate.getTime();
            var loc4=0;
            while (loc4 < loc1) 
            {
                loc2 = this._list[loc4];
                if (this.isInGuessTime(loc2.type, loc2.group)) 
                {
                    return loc2.type;
                }
                ++loc4;
            }
            return 0;
        }

        public getCurGuessDes(arg1: int): string
        {
            var loc1=Language.getString(20380) + "/" + Language.getString(44378);
            var loc2=Language.getString(51138);
            var loc3=loc2.split(",");
            if (arg1 > 0) 
            {
                if (arg1 > FootBallGameConst.GROUP_TYPE_2) 
                {
                    loc1 = "1/" + arg1 + loc3[1];
                }
                else if (arg1 != FootBallGameConst.GROUP_TYPE_2) 
                {
                    if (arg1 == FootBallGameConst.GROUP_TYPE_1) 
                    {
                        loc1 = loc3[1];
                    }
                }
                else 
                {
                    loc1 = loc3.join("");
                }
            }
            return loc1;
        }

        public getGameTypeDes(): Array<any>
        {
            var loc1=null;
            var loc2=0;
            if (!this._gameTypeDes) 
            {
                this._gameTypeDes = [];
                loc1 = [FootBallGameConst.GROUP_TYPE_8, FootBallGameConst.GROUP_TYPE_4, FootBallGameConst.GROUP_TYPE_2, FootBallGameConst.GROUP_TYPE_1];
                loc2 = 0;
                while (loc2 < loc1.length) 
                {
                    this._gameTypeDes.push(this.getCurGuessDes(loc1[loc2]));
                    ++loc2;
                }
            }
            return this._gameTypeDes;
        }

        public static get instance(): FootBallTimeConfig
        {
            return FootBallTimeConfig._instance;
        }

        public /* var */separator: string="-";

        /* internal */ /* var */_gameTypeDes: Array<any>;

        /* internal */ /* var */_footballTimeMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_list: Array<any>;

        /* internal */ static /* var */_instance: FootBallTimeConfig;
    }

            FootBallTimeConfig._instance = new FootBallTimeConfig();
        